#ifndef OPEN_GL_GRID_DISPLAY_H
#define OPEN_GL_GRID_DISPLAY_H

#include <deque>
using std::deque;

#include "../../../graphics/GlutCallbackListener.h"

#include "GridDisplay.h"

class Grid;
class World;

class OpenGlGridDisplay : public GridDisplay, public GlutCallbackListener {
public:
	/* ctor */
	OpenGlGridDisplay(const World& world);

	/* dtor */
	~OpenGlGridDisplay();

	/* glut callbacks */
	void callbackIdle();
	void callbackKeyboard(unsigned char key, int x, int y);
	void callbackMouse(int button, int state, int x, int y);
	void callbackDisplay();
	void callbackReshape(int width, int height);
	void callbackSpecial(int key, int x, int y);

//	/* world */
//	void setWorld(const World* world);

protected:
	/**
	 * Process events, redisplay accordingly.
	 * Should be called frequently to catch mouse, keyboard events.
	 */
	void updateGridDisplay();

	/* update world by one iteration */
	virtual void updateWorld() = 0;

private:
	World const& _world;

	bool _paused;
	bool _oneOff;

	/* camera */
	double _cameraX;
	double _cameraY;
	double _cameraZ;

	deque<Grid*> _gridHistory;
	int _gridIndex;
	int _lastGridIndex;

	void doSaveGrid();
};

#endif // OPEN_GL_GRID_DISPLAY_H

